<?php
class mstraccount_model extends CI_Model{
	private $KodeBank;
	private $Bankname;
	private $NoRekening;
    private $SaldoAwal;
	private $Uangmasuk;
	private $Uangkeluar;
    private $SaldoAkhir;
    private $createdby;
    private $createdon;
    private $lastupdateby;
  	private $lastupdateon;
  	private $active;
	
	function setKodeBank($kbank){
		$this->KodeBank = $kbank;
	}
	function getKodeBank(){
		return $this->KodeBank;
	}
	
	function setBankname($Bankname){
		$this->Bankname = $Bankname;
	}
	function getBankname(){
		return $this->Bankname;
	}
	
	function setNoRekening($NoRekening){
		$this->NoRekening = $NoRekening;
	}
	function getNoRekening(){
		return $this->NoRekening;
	}
	
	function setSaldoAwal($sldawal){
		$this->SaldoAwal = $sldawal;
	}
	function getSaldoAwal(){
		return $this->SaldoAwal;
	}
	
	function setUangmasuk($uangmasuk){
		$this->Uangmasuk = $uangmasuk;
	}
	function getUangmasuk(){
		return $this->Uangmasuk;
	}
	
	function setUangkeluar($uangout){
		$this->Uangkeluar = $uangout;
	}
	function getUangkeluar(){
		return $this->Uangkeluar;
	}
	
	function setSaldoAkhir($sldakhir){
		$this->SaldoAkhir = $sldakhir;
	}
	function getSaldoAkhir(){
		return $this->SaldoAkhir;
	}
	
	function setCreatedBy($c_by){
		$this->createdby = $c_by;
	}
	function getCreatedBy(){
		return $this->createdby;
	}

	function setCreatedOn(){
		$dateNow = date('Y-m-d H:i:s');
		$this->createdon = $dateNow;
	}
	function getCreatedOn(){
		return $this->createdon;
	}

	function setLastUpdateBy($u_by){
		$this->lastupdateby = $u_by;
	}
	function getLastUpdateBy(){
		return $this->lastupdateby;
	}

	function setLastUpdateOn(){
		$dateNow = date('Y-m-d H:i:s');
		$this->lastupdateon = $dateNow;
	}
	function getLastUpdateOn(){
		return $this->lastupdateon;
	}

	function setActive($active_val){
		$this->active = $active_val;
	}
	function getActive(){
		return $this->active;
	}
	
	// Call the module constructor
	function __construct(){
		parent::__construct();
	}
	
	function insert(){		
		$data = array(
			'KodeBank' => $this->getKodeBank(),
			'SaldoAwal' => $this->getSaldoAwal(),
			'SaldoAkhir' => $this->getSaldoAkhir(),
			'CreatedBy' => $this->getCreatedBy(),
			'CreatedOn' => $this->getCreatedOn(),
			'LastUpdateBy' => 'null',
			'LastUpdateOn' => 'null',
			'Active' => '1'					
		);
		$this->db->insert('account_mutasi_bank',$data);
	}
	
	function ubahmstraccount() 
	{
            $data = array(
                'SaldoAwal' => $this->getSaldoAwal(),
				'Uangmasuk' => $this->getUangmasuk(),
				'Uangkeluar' => $this->getUangkeluar(),
                'SaldoAkhir' => $this->getSaldoAkhir(),
                'lastupdateby' => $this->getLastUpdateBy(),
                'LastUpdateOn' => $this->getLastUpdateOn()
            );
 
        $this->db->where(array('KodeBank' => $this->getKodeBank()));
        $this->db->update('account_mutasi_bank', $data);
    }

    function deletemstraccount() {
        $data = array(
            'active' => '0'
        );
        $this->db->where(array('KodeBank' => $this->getKodeBank()));
        $this->db->update('account_mutasi_bank', $data);
    }
	
	function getList(){
		$this->db->select("account_mutasi_bank.KodeBank,master_bank.Bankname,master_bank.NoRekening,account_mutasi_bank.SaldoAwal,
		account_mutasi_bank.Uangmasuk,account_mutasi_bank.Uangkeluar,account_mutasi_bank.SaldoAkhir")
		->join('master_bank', 'master_bank.KodeBank=account_mutasi_bank.KodeBank')
		->where(array('account_mutasi_bank.Active'=>'1'));
		$this->db->order_by('account_mutasi_bank.KodeBank', 'asc');
		$query = $this->db->get('account_mutasi_bank');
		return $query->result();
	}
	
	function countGetList(){
		$this->db->select("account_mutasi_bank.KodeBank,master_bank.Bankname,master_bank.NoRekening,account_mutasi_bank.SaldoAwal,
		account_mutasi_bank.Uangmasuk,account_mutasi_bank.Uangkeluar,account_mutasi_bank.SaldoAkhir")
		->join('master_bank', 'master_bank.KodeBank=account_mutasi_bank.KodeBank')
		->where(array('account_mutasi_bank.Active'=>'1'));
		$this->db->order_by('account_mutasi_bank.KodeBank', 'asc');
		$query = $this->db->get('account_mutasi_bank');
		return $query->num_rows();
	}
	
	function getListlimit($limit,$start){
		$this->db->select("account_mutasi_bank.KodeBank,master_bank.Bankname,master_bank.NoRekening,account_mutasi_bank.SaldoAwal,
		account_mutasi_bank.Uangmasuk,account_mutasi_bank.Uangkeluar,account_mutasi_bank.SaldoAkhir")
		->join('master_bank', 'master_bank.KodeBank=account_mutasi_bank.KodeBank')
		->where(array('account_mutasi_bank.Active'=>'1'))
		->limit($limit,$start);
		$this->db->order_by('account_mutasi_bank.KodeBank', 'asc');
		$query = $this->db->get('account_mutasi_bank');
		return $query->result();
	}
	
	function getkdaccount()
	{
		$this->db->select("account_mutasi_bank.KodeBank,master_bank.Bankname,master_bank.NoRekening,account_mutasi_bank.SaldoAwal,
		account_mutasi_bank.Uangmasuk,account_mutasi_bank.Uangkeluar,account_mutasi_bank.SaldoAkhir")
		->join('master_bank', 'master_bank.KodeBank=account_mutasi_bank.KodeBank')
		->where(array('account_mutasi_bank.KodeBank' => $this->getKodeBank(),'account_mutasi_bank.Active'=>'1'));
		$query = $this->db->get('account_mutasi_bank');
		return $query->result();
	}
	
	function getkdbanklike()
	{
		$this->db->select("account_mutasi_bank.KodeBank,master_bank.Bankname,master_bank.NoRekening,account_mutasi_bank.SaldoAwal,
		account_mutasi_bank.Uangmasuk,account_mutasi_bank.Uangkeluar,account_mutasi_bank.SaldoAkhir")
		->join('master_bank', 'master_bank.KodeBank=account_mutasi_bank.KodeBank')
		->where(array('account_mutasi_bank.Active'=>'1'))->like(array('account_mutasi_bank.KodeBank' => $this->getKodeBank()));
		$query = $this->db->get('account_mutasi_bank');
		return $query->result();
	}
	
	function getnamabanklike()
	{
		$this->db->select("account_mutasi_bank.KodeBank,master_bank.Bankname,master_bank.NoRekening,account_mutasi_bank.SaldoAwal,
		account_mutasi_bank.Uangmasuk,account_mutasi_bank.Uangkeluar,account_mutasi_bank.SaldoAkhir")
		->join('master_bank', 'master_bank.KodeBank=account_mutasi_bank.KodeBank')
		->where(array('account_mutasi_bank.Active'=>'1'))->like(array('master_bank.Bankname' => $this->getBankname()));
		$query = $this->db->get('account_mutasi_bank');
		return $query->result();
	}
	
	function getnorekeninglike()
	{
		$this->db->select("account_mutasi_bank.KodeBank,master_bank.Bankname,master_bank.NoRekening,account_mutasi_bank.SaldoAwal,
		account_mutasi_bank.Uangmasuk,account_mutasi_bank.Uangkeluar,account_mutasi_bank.SaldoAkhir")
		->join('master_bank', 'master_bank.KodeBank=account_mutasi_bank.KodeBank')
		->where(array('account_mutasi_bank.Active'=>'1'))->like(array('master_bank.NoRekening' => $this->getNoRekening()));
		$query = $this->db->get('account_mutasi_bank');
		return $query->result();
	}
	
	function gettotalamount(){
		$this->db->select("SaldoAwal,Uangmasuk,Uangkeluar,SaldoAkhir")
		->where(array('KodeBank' => $this->getKodeBank()));
		$query = $this->db->get('account_mutasi_bank');
		return $query->result();
	}
}